import Mock from 'mockjs'

// 查询商品spu列表
export const getSpuPage = async (params: Spu): Promise<ListSpuRes> => {
  const res = await Mock.mock({
    'list|10': [
      {
        'id|+1': 1,
        categoryId: 1,
        categoryName: '@ctitle(2, 3)',
        spuName: '@ctitle(2, 3)',
        spuDesc: '@ctitle(6, 10)',
        coverUrl: '@image(200x200, @color, @color, @word)',
        videoUrl: '@image(200x200, @color, @color, @word)',
        'picUrls|1-10': ['@image(200x200, @color, @color, @word)'],
        detail: '@ctitle(34, 999)',
        price: '@integer(1, 1000)',
        totalStock: '@integer(1, 1000)',
        'showStock|1': [0, 1],
        salesCount: '@integer(1, 1000)',
        'status|1': [1, 2],
        sortNo: '@integer(1, 1000)',
        'spuType|1': [1, 2],
        createTime: 1691727146870
      }
    ],
    total: 100,
    pageNo: 1,
    pageSize: 10
  })
  return res
}

// 查询商品spu详情
export const getSpu = async (id: number) => {
  const res = await Mock.mock({
    'id|+1': 1,
    categoryId: 1,
    categoryName: '@ctitle(2, 3)',
    spuName: '@ctitle(2, 3)',
    spuDesc: '@ctitle(6, 10)',
    coverUrl: '@image(200x200, @color, @color, @word)',
    videoUrl: '@image(200x200, @color, @color, @word)',
    'picUrls|1-10': ['@image(200x200, @color, @color, @word)'],
    detail: '@ctitle(34, 999)',
    price: '@integer(1, 1000)',
    totalStock: '@integer(1, 1000)',
    'showStock|1': [0, 1],
    salesCount: '@integer(1, 1000)',
    'status|1': [1, 2],
    sortNo: '@integer(1, 1000)',
    'spuType|1': [1, 2],
    createTime: 1691727146870
  })
  return res
}

// 新增商品spu
export const createSpu = async (data: Spu) => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

// 修改商品spu
export const updateSpu = async (data: Spu): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

// 删除商品spu
export const deleteSpu = async (id: number): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}

/**
 * 文件上传
 * FormData 存有多个文件
 */
export const uploadFile = async (params: FormData): Promise<{ url: string }> => {
  const res = await Mock.mock(['@image(200x200, @color, @word)'])
  return res
}

/**
 * 删除上传文件
 */
export const deleteUploadFile = async (url: stirng[]): Promise<ResStatus> => {
  const res = await Mock.mock({
    isSuccess: true
  })
  return res
}
